package com.unicom.office.parser;

import com.unicom.office.config.OfficeConfig;
import com.unicom.office.node.*;
import com.unicom.office.runtime.OfficeRuntime;

public abstract class ExcelParser extends OfficeParser {
    public ExcelParser(OfficeConfig config, OfficeRuntime runtime) {
        super(config, runtime);
    }

    public OfficeNode parse(Object source, OfficeNode parentNode) {
        OfficeNodeType type = parseType(source);

        if(type == OfficeNodeType.Workbook){
            return parseWorkbook(source);
        }else if(type == OfficeNodeType.Worksheet){
            return parseWorksheet(source, parentNode);
        }else if(type == OfficeNodeType.Textbox){
            return parseTextbox(source, parentNode);
        }else if(type == OfficeNodeType.Table){
            return parseRow(source, parentNode);
        }else if(type == OfficeNodeType.Row){
            return parseRow(source, parentNode);
        }else if(type == OfficeNodeType.Cell){
            return parseCell(source, parentNode);
        }else if(type == OfficeNodeType.Paragraph){
            return parseParagraph(source, parentNode);
        }else if(type == OfficeNodeType.TextRange){
            return parseTextRange(source, parentNode);
        }else if(type == OfficeNodeType.Picture){
            return parsePicture(source, parentNode);
        }else{
            throw new RuntimeException("未识别的节点类型");
        }
    }

    protected abstract WorkbookNode parseWorkbook(Object source);
    protected abstract WorksheetNode parseWorksheet(Object source, OfficeNode parentNode);
}
